package com.wbc.smartHome.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wbc.smartHome.dao.CommunityActivitiesLabelDao;
import com.wbc.smartHome.model.CommodityLabel;
import com.wbc.smartHome.model.CommunityActivitiesLabel;
import com.wbc.smartHome.util.JWTUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class CommunityActivitiesLabelService {

    @Value("${aliyun.oss.endpoint}")
    private String endpoint;
    @Value("${aliyun.oss.accessKeyId}")
    private String accessKeyId;
    @Value("${aliyun.oss.accessKeySecret}")
    private String accessKeySecret;
    @Value("${aliyun.oss.bucketName}")
    private String bucketName;

    @Autowired
    private RedisTemplate redisTemplate;
    @Autowired
    private CommunityActivitiesLabelDao communityActivitiesLabelDao;
    private String key = "commodity";

    public PageInfo<CommunityActivitiesLabel> getCommunityActivitiesLabelList(CommunityActivitiesLabel communityActivitiesLabel) {
        PageHelper.startPage(communityActivitiesLabel.getPageNo(),communityActivitiesLabel.getPageSize());
        List<CommunityActivitiesLabel> CommunityActivitiesLabelList = communityActivitiesLabelDao.getCommunityActivitiesLabelList(communityActivitiesLabel);
        PageInfo<CommunityActivitiesLabel> pageInfo = new PageInfo<>(CommunityActivitiesLabelList);
        return pageInfo;

    }


    public void setCommunityActivitiesLabel(CommunityActivitiesLabel communityActivitiesLabel,String adminToken) {
      /*ListOperations listOps  = redisTemplate.opsForList();
        listOps.rightPush(key, commodity);*/
        int adminId = JWTUtil.getAdmin(adminToken).getId();
        communityActivitiesLabelDao.setCommunityActivitiesLabel(communityActivitiesLabel.getName(),adminId);
    }


    public void delete(int id) {
        communityActivitiesLabelDao.delete(id);

    }


    public void updateCommunityActivitiesLabel(CommunityActivitiesLabel communityActivitiesLabel, String adminToken) {
        int adminId = JWTUtil.getAdmin(adminToken).getId();
        communityActivitiesLabelDao.updateCommunityActivitiesLabel(communityActivitiesLabel.getId(),communityActivitiesLabel.getName(),adminId);
    }

    public CommunityActivitiesLabel getCommunityActivitiesLabelById(int id) {
        CommunityActivitiesLabel communityActivitiesLabel = communityActivitiesLabelDao.getCommunityActivitiesLabelById(id);
        return communityActivitiesLabel;
    }
}

